/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.mis6323.service.impl;

/**
 *
 * @author Linh Vo
 */
import java.util.List;
import org.mis6323.data.dao.ProviderDao;
import org.mis6323.data.model.Provider;
import org.mis6323.service.ProviderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProviderServiceImpl implements ProviderService{

    @Autowired
    private ProviderDao providerDao;

    public void setProviderDao(ProviderDao providerDao) {
        this.providerDao = providerDao;
    }

    @Override
    public void createNewProvider(Provider provider) {
       if(provider==null)
           throw new IllegalArgumentException("Provider cannot be null");

       if(provider.getId()!=null)
           throw new IllegalArgumentException("Provider ID is not null");

       this.providerDao.createProvider(provider);
    }

    @Override
    public void deleteProvider(Long providerId) {
        if(providerId!=null)
           throw new IllegalArgumentException("Provider ID is not null");
        this.providerDao.deleteProvider(providerId);
    }

    @Override
    public Provider lookUpProvider(String fullName) {
        if(fullName==null||fullName.isEmpty())
            throw new IllegalArgumentException("Empty phone number");
        return this.providerDao.searchProviderByFullName(fullName);
    }

    @Override
    public void updateProvider(Provider provider) {
        if(provider==null)
            throw new IllegalArgumentException("Patient cannot be null");
        this.providerDao.updateProvider(provider);
    }

    @Override
    public List<Provider> getAllProviders() {
        return this.providerDao.getAllProviders();
    }


}
